<template>
  <div class="cabinet-box">
    <div class="cabinet-name">{{cabinet.cabinetName}}</div>
    <div class="cabinet-main">
      <div class="side-box left">
        <div class="side-title">正面</div>
        <div class="row" v-for="(row) in frontCellList" :key="row">
          <div v-for="(cell) in row.cellList" :key="cell" @click="openCabinet(cell)">
            <div class="cell open" v-if="cell.open" :style="{width:cellWidth,height: cellHeight}">
              <div class="conent" @click.stop="userDialog(cell)">{{cell.userNames || '添加'}} </div>
            </div>
            <div v-else class="cell" :style="[cellStyle(cell.status),{width:cellWidth,height: cellHeight}]"> {{cell.cellNo}}</div>
          </div>
        </div>
      </div>

      <div class="side-box right">
        <div  class="side-title">背面</div>
        <div class="row" v-for="(row) in backCellList" :key="row">
          <div v-for="(cell) in row.cellList" :key="cell" @click="openCabinet(cell)">
            <div class="cell open" v-if="cell.open" :style="{width:cellWidth,height: cellHeight}">
              <div class="conent" @click.stop="userDialog(cell)">{{cell.userNames || '添加'}} </div>
            </div>
            <div v-else class="cell" :style="[cellStyle(cell.status),{width:cellWidth,height: cellHeight}]"> {{cell.cellNo}}</div>
          </div>
        </div>
      </div>
    </div>

    <div class="cabinet-bottom"><div/><div></div></div>

    <user-table ref="userTable" @onload="onload"/>

  </div>


</template>


<script>

import UserTable from "@/views/prison/cabinet-info/components/user-table";
export default {
  name: "cabinet-box",
  components: {UserTable},
  props: {
    cabinet:{
      type: Object,
      default:  {
        cabinetName:''
      },
    },
    cellWidth:{
      type: String,
      default: '5.6vw',
    },
    cellHeight:{
      type: String,
      default: '5.6vw',
    }
  },

  data() {
    return {
      frontCellList: this.cabinet.frontCellList,
      backCellList: this.cabinet.backCellList,
    }
  },


  watch: {

    cabinet(val = []) {
      this.frontCellList = val.frontCellList
      this.backCellList = val.backCellList
    },
  },


  methods: {
    cellStyle(status){
      if (status===1){
        return {
          color: '#00FF00'
        }
      }else if (status===2){
        return {
          color:'#FF0000'
        }
      }
    },

    openCabinet(cell){
      cell.open = !cell.open
      this.$forceUpdate()
    },

    userDialog(cell){
      this.$refs.userTable.open(cell,this.cabinet.cabinetName)
    },

    onload(){
      this.$emit("onload")
    },


  }


}

</script>





<style scoped lang="scss">


.cabinet-box{
  background-color: #7998C6;
  border: 6px solid tan;
  margin: 20px;
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.5);
  .cabinet-name{
    text-align: center;
    margin-bottom: 4px;
    font-size: 22px;
    color: white;
    font-weight: bold;
    box-shadow: 0 3px rgba(0, 0, 0, 0.3);
    padding: 20px;
  }
  .cabinet-bottom{
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
    padding: 20px 50px;
    margin-top: 4px;
    display: flex;
    justify-content: space-between;
    div{
      background-color: #556B8C;
      height: 15px;
      width: 100px;
    }
  }
}




.left{
  border-radius: 0 4px 4px 0;
  margin-right: 2px;
}
.right{
  border-radius:  4px 0 0 4px;
  margin-left: 2px;
}

.cabinet-main{
  overflow: auto;
  white-space: nowrap;
  background-color: #7998C6;
}

.side-box{
  padding:0 20px 20px 20px;
  background-color: #7998C6;
  display: inline-block;
  box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.5);
  .side-title{
    text-align: center;
    background-color: #7998C6;
    padding: 8px;
    color: #DAE2EF;
  }

  .row{
    display: flex;

    color: #e0dede;
    font-size: 12px;
    cursor: pointer;
  }

}


.cell{
  width: 5.6vw;
  height: 6vw;
  text-align: center;
  border: 1px solid white;
  display: flex;
  align-items: center;
  justify-content: space-around;
  border-radius: 4px;
  background-color: #8ba5ce;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
}

.open{
  background-color: white;
  box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.6);
  color: black;
  .conent{
    white-space: normal;
    max-height: 95%;
    max-width: 100%;
    text-align: center;
    overflow: auto;
    margin: 4px;
    color: #8BA5CE;
  }

}





</style>
